<!DOCTYPE html>
<html lang="zh">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>
    
    ES6 对象方法扩展 - DSRBLOG
    
  </title>
  

  
  
  <link href="atom.xml" rel="alternate" title="DSRBLOG" type="application/atom+xml">
  <link rel="stylesheet" href="asset/css/style.min.css">
  <link rel="stylesheet" href="asset/css/doc.css">
  <script src="asset/app.js"></script>


</head>

<body> <section class="ct-body">
	<div class="container">
		<div class="columns is-variable bd-klmn-columns is-4 is-centered">
			<div class="column is-four-fifths">
				<div class="post-body single-content">
					
					<h1 class="title">
						ES6 对象方法扩展
					</h1>


					<div class="media">
						
						
						<div class="media-content">
							<div class="content">
								<p>
									<span class="date">2022/09/27 15:24 下午</span>
									

									

									<br />
									<span class="tran-tags">Tags:</span>&nbsp;
									
									<a class="tag is-link is-light">#ES6新特性</a>
									

								</p>
							</div>
						</div>

					</div>
				</div>
				<article class="markdown-body single-content">
					<h2><a id="object-is" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>Object.is</h2>
<p>判断两个值是否完全相等</p>
<ul>
<li>类似<code>===</code>，但是<code>NaN === NaN</code>为<code>false</code>，<code>Object.is(NaN,NaN)</code>为<code>true</code></li>
</ul>
<pre class="line-numbers"><code class="language-js">console.log(Object.is(120, '一百二十')); //输出 false
console.log(Object.is(10, 0b1010)); //输出 true
</code></pre>
<h2><a id="object-assign" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>Object.assign</h2>
<p>对象的合并</p>
<ul>
<li>若两个<code>Object</code>对象存在相同名称的参数属性，则后面的参数熟悉覆盖前面的参数属性</li>
<li>若两个<code>Object</code>对象存在不同名称的参数属性，则合并到前一个<code>Object</code>内</li>
</ul>
<pre class="line-numbers"><code class="language-js">const config1 = {
    host: 'localhost',
    port: 3306,
    name: 'admin',
}

const config2 = {
    host: '127.0.0.1',
    port: 8080,
    pass: 'dsr213333'
}

console.log(Object.assign(config1, config2));
/* {
    host: &quot;127.0.0.1&quot;, 
    port: 8080, 
    name: &quot;admin&quot;, 
    pass: &quot;dsr213333&quot; 
} */
</code></pre>
<h2><a id="object-setprototypeof-object-getprototypeof" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>Object.setPrototypeOf &amp; Object.getPrototypeOf</h2>
<p>设置原型对象 &amp; 获取原型对象</p>
<pre class="line-numbers"><code class="language-js">const school = {
    name: 'GDUST'
}

const campus = {
    campus: ['松山湖', '南城']
}

Object.setPrototypeOf(school, campus); //将后者设置为前者的原型对象

console.log(Object.getPrototypeOf(school)); //输出school的原型对象
</code></pre>

				</article>
				<div class="comments-wrap">
					<div class="share-comments">
						

						

						
					</div>
				</div><!-- end comments wrap -->
			</div>
		</div><!-- end columns -->
	</div><!-- end container -->
</section>  














<script src="asset/prism.js"></script>









</body>

</html>